package com.majsubtense.core.achievements;

import com.majsubtense.core.components.UI;
import com.majsubtense.core.events.EventHandler;
import com.majsubtense.core.events.GameSceneControlEvent;

public class PressResetButtonAchievement extends CountTriggeredAchievement {
    private static final AchievementType<PressResetButtonAchievement> ANY;
    private final int maxCount = 5;

    public PressResetButtonAchievement() {
        super(PressResetButtonAchievement.ANY, "小赌怡情，大赌伤身");

        setCountGenerator(() -> count + 1);

        UI.addListener(new EventHandler<>(
                GameSceneControlEvent.GAME_SCENE_RESET,
                gameSceneResetEvent -> {
                    count = countGenerator.generate();
                    if (count == maxCount)
                        finishAchievement();
                }
        ));
    }

    @Override
    public void finishAchievement() {
        if (!isFinished()) {
            AchievementController.showAchievementDialog(this);
            setFinished(true);
        }
    }

    static {
        ANY = new AchievementType<>(CountTriggeredAchievement.ANY, "PRESS_RESET_BUTTON");
    }
}
